package com.hcl.orm.sample;

import com.hcl.orm.core.executor.page.PageParam;
import com.hcl.orm.core.executor.page.PageResult;
import com.hcl.orm.sample.dao.CustomerAgencyDao;
import com.hcl.orm.sample.domain.Agency;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * @author hucl
 * @projectName hcl-orm
 * @description: 单表默认SQL执行
 * @date 2021/8/1215:37
 */
public class SimpleDaoSample {
    private static final Logger logger = LoggerFactory.getLogger(SimpleDaoSample.class);
    private ConfigurableApplicationContext context;
    private CustomerAgencyDao agencyDao;

    public SimpleDaoSample(ConfigurableApplicationContext context) {
        this.context = context;
        agencyDao = context.getBean(CustomerAgencyDao.class);
    }


    public void test() {
        Agency agency = new Agency();
        agency.setAgencyName("测试");
        agency.setAgencyNo("111");
        agency.setCompanyName("测试公司");
        agency.setUpdateDate(20210518);
        agency.setProdtaNo("11");
        agency.setUpdateTime(1235);
        agency.setCompanyNo(1);
        int ret = agencyDao.insertAgency(agency);
        if (ret == 1) {
            logger.info("insertAgency 执行成功");
        }
        agency.setAgencyName("测试2");
        agencyDao.updateAgencyByPrimaryKey(agency);
        logger.info("updateAgencyByPrimaryKey 执行成功");
        Agency agency2 = new Agency();
        agency2.setAgencyNo("111");
        agency2.setProdtaNo("11");
        Agency ret2 = agencyDao.selectOneAgency(agency);
        logger.info("selectOneAgency 执行成功，结果:" + agency);
        agencyDao.deleteOneAgency(ret2);
        logger.info("deleteOneAgency 执行成功");
        PageResult<Agency> pageRet = agencyDao.queryAgencyPage(new PageParam(10, 1));
        logger.info("queryAgencyPage 执行成功,结果：" + pageRet);

        agencyDao.selectAgencyByDate(20210816, 210921);
    }
}

